package com.irdstudio.efp.esb.api.rest.zzd;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.irdstudio.efp.esb.api.bean.zzd.ReqFileDownLoadNoticeBean;
import com.irdstudio.efp.esb.api.bean.zzd.RespFileDownLoadNoticebean;
import com.irdstudio.efp.esb.api.rest.EsbServerController;
import com.irdstudio.efp.esb.common.constant.EsbBizEnums;
import com.irdstudio.basic.framework.core.exception.ESBException;
import com.irdstudio.basic.framework.core.util.InterfaceCheckUtils;

public class FileDownLoadNoticeController implements EsbServerController{

	private static Logger logger = LoggerFactory.getLogger(FileDownLoadNoticeController.class);

	/**
	 * 文件下载通知接口逻辑处理方法，处理逻辑包括：<br>
	 * 1.将用户借款请求报文体对象转换成用户借款请求对应的domain；<br>
	 * 2.对用户借款请求domain中值做是否必输性校验；<br>
	 * 3.对用户借款请求domain中值做是否合规性校验；<br>
	 * 4.调用对应的中台服务；<br>
	 * 
	 * @param esbReqBodyBean
	 * @return
	 * @throws Exception
	 * @author liyakui
	 * @since 2018年12月18日 下午5:16:37
	 * @version 1.0
	 */
	@Override
	public String execute(String esbReqBodyBean) throws ESBException, Exception {
		// 请求对象
		ReqFileDownLoadNoticeBean reqFileDownLoadNoticebean = null;
		// 返回对象
		RespFileDownLoadNoticebean respFileDownLoadNoticebean = new RespFileDownLoadNoticebean();
		try {
			// 1.转换请求bean
			reqFileDownLoadNoticebean = JSON.toJavaObject(JSONObject.parseObject(esbReqBodyBean), ReqFileDownLoadNoticeBean.class);
			// 2.获取交易流水号或订单号
			logger.info("商户号[" + reqFileDownLoadNoticebean.getLoanerSpid() + "]文件下载处理开始!");

			// 3.必输项校验
			// 3.1.接口字段必输项校验
			String loanerSpid = (String )InterfaceCheckUtils.getValue("loanerSpid","商户号",reqFileDownLoadNoticebean.getLoanerSpid(),true);
			String fileName = (String )InterfaceCheckUtils.getValue("fileName","文件名",reqFileDownLoadNoticebean.getFileName(),true);
			String fileAbstract = (String )InterfaceCheckUtils.getValue("fileAbstract","授权文件摘要的值",reqFileDownLoadNoticebean.getFileAbstract(),true);
			
			// 3.3.调用中台服务插入文件下载列表 TODO
			
			// 4.拼装返回报文
			respFileDownLoadNoticebean.setRetcode(EsbBizEnums.RetCodeEnum.SUCCESS.VALUE);
			respFileDownLoadNoticebean.setRetmsg(EsbBizEnums.RetCodeMsg.SUCCESS_MSG.VALUE);
			respFileDownLoadNoticebean.setBankRetcode(EsbBizEnums.RetCodeEnum.SUCCESS.VALUE);
			respFileDownLoadNoticebean.setBankRetmsg(EsbBizEnums.RetCodeMsg.SUCCESS_MSG.VALUE);
			respFileDownLoadNoticebean.setLoanerSpid(loanerSpid);
			throw new ESBException();
		} catch (ESBException e) {
			logger.error("");
		} catch (Exception e) {
			logger.error("");
		}
		logger.info("商户号[" + reqFileDownLoadNoticebean.getLoanerSpid() + "]文件下载处理结束!");
		return JSON.toJSONString(respFileDownLoadNoticebean);
	}
}
